package com.trkj.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.service.YzrPurchOrderService;
import com.trkj.vo.Result;
import com.trkj.vo.YzrOrderAndOrderDetVo;
import com.trkj.vo.YzrPurchOrderVo;

@Controller
public class YzrPurchOrderContorller {

	@Autowired
	private YzrPurchOrderService yzrPurchOrderService;
	
	@RequestMapping("/to_purchOrder")
	public String toPurchOrder(){
		return "yzr_purchOrder";
	}	
	
	//查找出‘未采购’并且‘已通过’的采购计划单
	@RequestMapping("/queryStateAndAutState")
	public @ResponseBody Map<String,Object> queryStateAndAutState(int page, int rows){
		return yzrPurchOrderService.queryStateAndAutState(page,rows);
	}
	
	//查找出‘已验收’并且‘未入库’的采购计划单
	@RequestMapping("/queryAllOrByNoInst_yzr")
	public @ResponseBody Map<String,Object> queryAllOrderByNoInstock(int page, int rows){
		return yzrPurchOrderService.queryAllOrderByNoInstock(page, rows);
	}
	
	//根据计划单号查找出计划单下明细中的药品
	@RequestMapping("/queryMedByPlanId")
	public @ResponseBody Map<String,Object> queryMedByPlanId(String planId,int page, int rows){
		return yzrPurchOrderService.queryMedByPlanId(planId,page,rows);		
	}
	
	//添加采购订单
	@RequestMapping("/addPurchOrder")
	public @ResponseBody Result addPurchOrder(YzrOrderAndOrderDetVo purchOrder){
		System.err.println(purchOrder.getOrderDets().size());
		yzrPurchOrderService.addPurchOrder(purchOrder);
		return new Result();
	}
	
	//分页查询所有订单
	@RequestMapping("/queryAllOrder")
	public @ResponseBody Map<String,Object> queryAllOrder(int page, int rows){
		return yzrPurchOrderService.queryAllOrder(page, rows);
	}
	
	//根据订单id查找订单
	@RequestMapping("/queryOrderById")
	public @ResponseBody YzrPurchOrderVo queryOrderById(String orderId){
		return yzrPurchOrderService.queryOrderById(orderId);
	}
	
	//根据订单id查找订单明细
	@RequestMapping("/queryOrderByOrderId")
	public @ResponseBody Map<String, Object> queryOrderByOrderId(int page, int rows,String orderId){
		return yzrPurchOrderService.queryOrderByOrderId(page, rows, orderId);
	}
	
	//根据不同条件查询订单信息
	@RequestMapping("/queryByIf")
	public @ResponseBody Map<String, Object> queryByIf(int page, int rows,String name,String value){
		return yzrPurchOrderService.queryByIf(page, rows, name, value);
	}
	
	//根据交货时间段查询订单
	@RequestMapping("/queryByJiaoHuoDate")
	public @ResponseBody Map<String, Object> queryByJiaoHuoDate(Date startDate,Date endDate,int page, int rows){
		return yzrPurchOrderService.queryByJiaoHuoDate(startDate, endDate,page, rows);
	}
}
